package c.e.a.c.q;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.util.Log;
import android.util.TypedValue;
import b.i.c.b.g;
import b.i.c.b.h;

/* compiled from: TextAppearance */
public class b {
    public final float a;
    public final ColorStateList b;
    public final int c;
    public final int d;
    public final String e;
    public final ColorStateList f;
    public final float g;
    public final float h;
    public final float i;
    public final int j;
    public boolean k = false;
    public Typeface l;

    /* compiled from: TextAppearance */
    public class a extends g {
        public final /* synthetic */ d a;

        public a(d dVar) {
            this.a = dVar;
        }

        public void c(int i) {
            b.this.k = true;
            this.a.a(i);
        }

        public void d(Typeface typeface) {
            b bVar = b.this;
            bVar.l = Typeface.create(typeface, bVar.c);
            b bVar2 = b.this;
            bVar2.k = true;
            this.a.b(bVar2.l, false);
        }
    }

    public b(Context context, int i) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(i, c.e.a.c.b.y);
        this.a = obtainStyledAttributes.getDimension(0, 0.0f);
        this.b = c.e.a.c.a.j(context, obtainStyledAttributes, 3);
        c.e.a.c.a.j(context, obtainStyledAttributes, 4);
        c.e.a.c.a.j(context, obtainStyledAttributes, 5);
        this.c = obtainStyledAttributes.getInt(2, 0);
        this.d = obtainStyledAttributes.getInt(1, 1);
        int i2 = 12;
        if (!obtainStyledAttributes.hasValue(12)) {
            i2 = 10;
        }
        this.j = obtainStyledAttributes.getResourceId(i2, 0);
        this.e = obtainStyledAttributes.getString(i2);
        obtainStyledAttributes.getBoolean(14, false);
        this.f = c.e.a.c.a.j(context, obtainStyledAttributes, 6);
        this.g = obtainStyledAttributes.getFloat(7, 0.0f);
        this.h = obtainStyledAttributes.getFloat(8, 0.0f);
        this.i = obtainStyledAttributes.getFloat(9, 0.0f);
        obtainStyledAttributes.recycle();
    }

    public final void a() {
        if (this.l == null) {
            String str = this.e;
            if (str != null) {
                this.l = Typeface.create(str, this.c);
            }
        }
        if (this.l == null) {
            int i = this.d;
            if (i == 1) {
                this.l = Typeface.SANS_SERIF;
            } else if (i == 2) {
                this.l = Typeface.SERIF;
            } else if (i != 3) {
                this.l = Typeface.DEFAULT;
            } else {
                this.l = Typeface.MONOSPACE;
            }
            this.l = Typeface.create(this.l, this.c);
        }
    }

    public void b(Context context, d dVar) {
        a();
        int i = this.j;
        if (i == 0) {
            this.k = true;
        }
        if (this.k) {
            dVar.b(this.l, true);
            return;
        }
        try {
            a aVar = new a(dVar);
            if (context.isRestricted()) {
                aVar.a(-4, null);
            } else {
                h.d(context, i, new TypedValue(), 0, aVar, null, false);
            }
        } catch (NotFoundException unused) {
            this.k = true;
            dVar.a(1);
        } catch (Exception e) {
            StringBuilder g = c.b.a.a.a.g("Error loading font ");
            g.append(this.e);
            Log.d("TextAppearance", g.toString(), e);
            this.k = true;
            dVar.a(-3);
        }
    }

    public void c(Context context, TextPaint textPaint, d dVar) {
        a();
        d(textPaint, this.l);
        b(context, new c(this, textPaint, dVar));
        ColorStateList colorStateList = this.b;
        textPaint.setColor(colorStateList != null ? colorStateList.getColorForState(textPaint.drawableState, colorStateList.getDefaultColor()) : -16777216);
        float f = this.i;
        float f2 = this.g;
        float f3 = this.h;
        ColorStateList colorStateList2 = this.f;
        textPaint.setShadowLayer(f, f2, f3, colorStateList2 != null ? colorStateList2.getColorForState(textPaint.drawableState, colorStateList2.getDefaultColor()) : 0);
    }

    public void d(TextPaint textPaint, Typeface typeface) {
        textPaint.setTypeface(typeface);
        int i = (~typeface.getStyle()) & this.c;
        textPaint.setFakeBoldText((i & 1) != 0);
        textPaint.setTextSkewX((i & 2) != 0 ? -0.25f : 0.0f);
        textPaint.setTextSize(this.a);
    }
}
